/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: DuKe TeAm
 * License Type: Purchased
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class Tbv_parametroDAOImpl implements orm.dao.Tbv_parametroDAO {
	public Tbv_parametro loadTbv_parametroByORMID(int pa_id_parametro) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_parametroByORMID(session, pa_id_parametro);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro getTbv_parametroByORMID(int pa_id_parametro) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_parametroByORMID(session, pa_id_parametro);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro loadTbv_parametroByORMID(int pa_id_parametro, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_parametroByORMID(session, pa_id_parametro, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro getTbv_parametroByORMID(int pa_id_parametro, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return getTbv_parametroByORMID(session, pa_id_parametro, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro loadTbv_parametroByORMID(PersistentSession session, int pa_id_parametro) throws PersistentException {
		try {
			return (Tbv_parametro) session.load(orm.Tbv_parametro.class, new Integer(pa_id_parametro));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro getTbv_parametroByORMID(PersistentSession session, int pa_id_parametro) throws PersistentException {
		try {
			return (Tbv_parametro) session.get(orm.Tbv_parametro.class, new Integer(pa_id_parametro));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro loadTbv_parametroByORMID(PersistentSession session, int pa_id_parametro, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_parametro) session.load(orm.Tbv_parametro.class, new Integer(pa_id_parametro), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro getTbv_parametroByORMID(PersistentSession session, int pa_id_parametro, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Tbv_parametro) session.get(orm.Tbv_parametro.class, new Integer(pa_id_parametro), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro[] listTbv_parametroByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_parametroByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro[] listTbv_parametroByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return listTbv_parametroByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro[] listTbv_parametroByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_parametro as Tbv_parametro");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Tbv_parametro[]) list.toArray(new Tbv_parametro[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro[] listTbv_parametroByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_parametro as Tbv_parametro");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Tbv_parametro[]) list.toArray(new Tbv_parametro[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro loadTbv_parametroByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_parametroByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro loadTbv_parametroByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return loadTbv_parametroByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro loadTbv_parametroByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Tbv_parametro[] tbv_parametros = listTbv_parametroByQuery(session, condition, orderBy);
		if (tbv_parametros != null && tbv_parametros.length > 0)
			return tbv_parametros[0];
		else
			return null;
	}
	
	public Tbv_parametro loadTbv_parametroByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Tbv_parametro[] tbv_parametros = listTbv_parametroByQuery(session, condition, orderBy, lockMode);
		if (tbv_parametros != null && tbv_parametros.length > 0)
			return tbv_parametros[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateTbv_parametroByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_parametroByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_parametroByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.Bdvendomaticav04PersistentManager.instance().getSession();
			return iterateTbv_parametroByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_parametroByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_parametro as Tbv_parametro");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateTbv_parametroByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Tbv_parametro as Tbv_parametro");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro createTbv_parametro() {
		return new orm.Tbv_parametro();
	}
	
	public boolean save(orm.Tbv_parametro tbv_parametro) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().saveObject(tbv_parametro);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Tbv_parametro tbv_parametro) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().deleteObject(tbv_parametro);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_parametro tbv_parametro)throws PersistentException {
		try {
			orm.Tbv_producto[] lTbv_productos = tbv_parametro.tbv_producto.toArray();
			for(int i = 0; i < lTbv_productos.length; i++) {
				lTbv_productos[i].setTbv_parametropa_id_parametro(null);
			}
			return delete(tbv_parametro);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Tbv_parametro tbv_parametro, org.orm.PersistentSession session)throws PersistentException {
		try {
			orm.Tbv_producto[] lTbv_productos = tbv_parametro.tbv_producto.toArray();
			for(int i = 0; i < lTbv_productos.length; i++) {
				lTbv_productos[i].setTbv_parametropa_id_parametro(null);
			}
			try {
				session.delete(tbv_parametro);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Tbv_parametro tbv_parametro) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().refresh(tbv_parametro);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Tbv_parametro tbv_parametro) throws PersistentException {
		try {
			orm.Bdvendomaticav04PersistentManager.instance().getSession().evict(tbv_parametro);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Tbv_parametro loadTbv_parametroByCriteria(Tbv_parametroCriteria tbv_parametroCriteria) {
		Tbv_parametro[] tbv_parametros = listTbv_parametroByCriteria(tbv_parametroCriteria);
		if(tbv_parametros == null || tbv_parametros.length == 0) {
			return null;
		}
		return tbv_parametros[0];
	}
	
	public Tbv_parametro[] listTbv_parametroByCriteria(Tbv_parametroCriteria tbv_parametroCriteria) {
		return tbv_parametroCriteria.listTbv_parametro();
	}
}
